//
//  TMDWBVNAVController.swift
//  TMDWeiBo
//
//  Created by 汤明鼎 on 2017/1/17.
//  Copyright © 2017年 heimaitcast. All rights reserved.
//

import UIKit

class TMDWBVNAVController: UINavigationController ,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()

        interactivePopGestureRecognizer?.delegate = self
    }
    
    //将要接受手势点击
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        return childViewControllers.count != 1
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //进入了二级控制器
        if childViewControllers.count > 0 {
            
            var title = "返回"
            
            if childViewControllers.count == 1 {
                viewController.hidesBottomBarWhenPushed = true
                title = childViewControllers.first?.title ?? ""
            }
        
             viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageNamed: "navigationbar_back_withtext", title:title, target: self, action: #selector(leftClick))
        }
        super.pushViewController(viewController, animated: animated)
    }
}

extension TMDWBVNAVController{
    
    @objc fileprivate func leftClick(){
        _ = popViewController(animated: true)
    }
    

}
